package com.ruoyi.project.stop.controller;

import java.util.List;

import com.ruoyi.project.stop.domain.WarnHistoryVO;
import com.ruoyi.project.stop.dto.WarnHistoryDTO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.stop.domain.WarnHistory;
import com.ruoyi.project.stop.service.IWarnHistoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 报警历史记录单据Controller
 *
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/stop/warn-history")
public class WarnHistoryController extends BaseController
{
    private String prefix = "stop/warn-history";

    @Autowired
    private IWarnHistoryService warnHistoryService;


    @GetMapping()
    public String history()
    {
        return prefix + "/history";
    }

    /**
     * 查询报警历史记录单据列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WarnHistoryVO warnHistoryVO)
    {
        startPage();
        //List<WarnHistory> list = warnHistoryService.selectWarnHistoryList(warnHistory);
        List<WarnHistoryDTO> list = warnHistoryService.selectWarnHistoryDTOList(warnHistoryVO);
        return getDataTable(list);
    }

    /**
     * 导出报警历史记录单据列表
     */

    @Log(title = "报警历史记录单据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WarnHistory warnHistory)
    {
        List<WarnHistory> list = warnHistoryService.selectWarnHistoryList(warnHistory);
        ExcelUtil<WarnHistory> util = new ExcelUtil<WarnHistory>(WarnHistory.class);
        return util.exportExcel(list, "报警历史记录单据数据");
    }

    /**
     * 新增报警历史记录单据
     */

    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报警历史记录单据
     */

    @Log(title = "报警历史记录单据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WarnHistory warnHistory)
    {
        return toAjax(warnHistoryService.insertWarnHistory(warnHistory));
    }

    /**
     * 修改报警历史记录单据
     */

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WarnHistory warnHistory = warnHistoryService.selectWarnHistoryById(id);
        mmap.put("warnHistory", warnHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存报警历史记录单据
     */

    @Log(title = "报警历史记录单据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WarnHistory warnHistory)
    {
        return toAjax(warnHistoryService.updateWarnHistory(warnHistory));
    }

    /**
     * 删除报警历史记录单据
     */

    @Log(title = "报警历史记录单据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(warnHistoryService.deleteWarnHistoryByIds(ids));
    }
}
